package com.example.a80205050.myapplication.MyActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.a80205050.myapplication.Dao.FlagDao;
import com.example.a80205050.myapplication.Modle.Tb_flag;

/**
 * Created by 80205050 on 2017/11/1.
 */

public class FlagManage extends Activity {
    EditText txtFlag;
    Button btnEdit,btnDel;
    String strId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.flagmanage);
        txtFlag=(EditText)findViewById(R.id.txtFlagManage);
        btnDel=(Button)findViewById(R.id.btnFlagManageDelete);
        btnEdit=(Button)findViewById(R.id.btnFlagManageEdit);
        final FlagDao flagDao=new FlagDao(FlagManage.this);
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        strId=bundle.getString(Showinfo.FLAG);
        txtFlag.setText(flagDao.find(Integer.parseInt(strId)).getFlag());
        btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Tb_flag tb_flag=new Tb_flag();
                tb_flag.set_id(Integer.parseInt(strId));
                tb_flag.setFlag(txtFlag.getText().toString());
                flagDao.updata(tb_flag);
                Toast.makeText(FlagManage.this,"便签信息修改成功",Toast.LENGTH_LONG).show();
            }
        });
        btnDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                flagDao.delete(Integer.parseInt(strId));
                Toast.makeText(FlagManage.this,"便签信息删除成功",Toast.LENGTH_LONG).show();
            }
        });
    }
}
